package com.ruoyi.caiwu.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.caiwu.domain.CurrencyTable;
import com.ruoyi.caiwu.service.ICurrencyTableService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 币别表Controller
 *
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/table")
public class CurrencyTableController extends BaseController
{
    @Autowired
    private ICurrencyTableService currencyTableService;

    /**
     * 查询币别表列表
     */
    @RequiresPermissions("caiwu:table:list")
    @GetMapping("/list")
    public TableDataInfo list(CurrencyTable currencyTable)
    {
        startPage();
        List<CurrencyTable> list = currencyTableService.selectCurrencyTableList(currencyTable);
        return getDataTable(list);
    }

    /**
     * 导出币别表列表
     */
    @RequiresPermissions("caiwu:table:export")
    @Log(title = "币别表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CurrencyTable currencyTable)
    {
        List<CurrencyTable> list = currencyTableService.selectCurrencyTableList(currencyTable);
        ExcelUtil<CurrencyTable> util = new ExcelUtil<CurrencyTable>(CurrencyTable.class);
        util.exportExcel(response, list, "币别表数据");
    }

    /**
     * 获取币别表详细信息
     */
    @RequiresPermissions("caiwu:table:query")
    @GetMapping(value = "/{currencyId}")
    public AjaxResult getInfo(@PathVariable("currencyId") Long currencyId)
    {
        return success(currencyTableService.selectCurrencyTableByCurrencyId(currencyId));
    }

    /**
     * 新增币别表
     */
    @RequiresPermissions("caiwu:table:add")
    @Log(title = "币别表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CurrencyTable currencyTable)
    {
        return toAjax(currencyTableService.insertCurrencyTable(currencyTable));
    }

    /**
     * 修改币别表
     */
    @RequiresPermissions("caiwu:table:edit")
    @Log(title = "币别表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CurrencyTable currencyTable)
    {
        return toAjax(currencyTableService.updateCurrencyTable(currencyTable));
    }

    /**
     * 删除币别表
     */
    @RequiresPermissions("caiwu:table:remove")
    @Log(title = "币别表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{currencyIds}")
    public AjaxResult remove(@PathVariable Long[] currencyIds)
    {
        return toAjax(currencyTableService.deleteCurrencyTableByCurrencyIds(currencyIds));
    }
}
